package negocio
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsHttpSession
import grails.converters.JSON

class UsuarioService {
    //pegou o serviço do grails
    def facebookGraphService

    static transactional = true

    def userFacebook(Object session) {
        session=session as org.codehaus.groovy.grails.web.servlet.mvc.GrailsHttpSession
        if(facebookGraphService && session.facebook){
            //pega os dados do usuário
            def userFace = JSON.parse (facebookGraphService.getFacebookProfile().toString() )
            //cria o usuário
            Usuario user= new Usuario()
            user.setIdPerfilFace(userFace.id)
            user.setEmail(userFace.email)
            user.setNome(userFace.name)
            return userFace
        }
        return null
    }
}
